"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var MyCrypto_1 = require("../../MyCrypto");
/**
 * 记得编码数据,部分存储在数据库中的数据是经过编码的,所以如果那些数据不编码就进行查询就会查不到
 * */
var Update = /** @class */ (function () {
    function Update(props) {
        this._crypto = new MyCrypto_1.default();
        var knex = props.knex;
        this._knex = knex;
    }
    /**
     * @param TABLE_NAME 表名
     * @param DATA 要修改的值
     * @param CONDITION where条件
     * */
    Update.prototype.update = function (TABLE_NAME, DATA, CONDITION) {
        var KEY = CONDITION.KEY, SIGN = CONDITION.SIGN, VALUE = CONDITION.VALUE;
        var _DATA = this.encode(DATA);
        var _VALUE = this.strEncode(VALUE);
        return this._knex(TABLE_NAME).
            where(KEY, SIGN, _VALUE).
            update(_DATA);
    };
    /**
     * @param TABLE_NAME 表名
     * @param DATA 要修改的值
     * @param CONDITION where条件
     * 该函数不对要更新的数据进行编码
     * */
    Update.prototype.updateNoneEncodeDATA = function (TABLE_NAME, DATA, CONDITION) {
        var KEY = CONDITION.KEY, SIGN = CONDITION.SIGN, VALUE = CONDITION.VALUE;
        var _VALUE = this.strEncode(VALUE);
        return this._knex(TABLE_NAME).
            where(KEY, SIGN, _VALUE).
            update(DATA);
    };
    /**
     * @param TABLE_NAME 表名
     * @param DATA {t1:'t1'} 要修改的值
     * @param CONDITION where条件
     * 该函数不对条件的VALUE数据进行编码
     * */
    Update.prototype.updateNoneEncodeValue = function (TABLE_NAME, DATA, CONDITION) {
        var KEY = CONDITION.KEY, SIGN = CONDITION.SIGN, VALUE = CONDITION.VALUE;
        var _DATA = this.encode(DATA);
        return this._knex(TABLE_NAME).
            where(KEY, SIGN, VALUE).
            update(_DATA);
    };
    /**
     * @param TABLE_NAME 表名
     * @param DATA 要修改的值
     * @param CONDITION where条件
     * 该函数不对要更新的数据与条件的VALUE进行编码
     * */
    Update.prototype.updateNoneEncodeDATAWithValue = function (TABLE_NAME, DATA, CONDITION) {
        var KEY = CONDITION.KEY, SIGN = CONDITION.SIGN, VALUE = CONDITION.VALUE;
        return this._knex(TABLE_NAME).
            where(KEY, SIGN, VALUE).
            update(DATA);
    };
    /**
     * 为controller目录下的UpdateAnthology定制的sql,用于批量更新操作
     * @param newAnthology 目标anthology
     * @param oldAnthology 源anthology
     * @param author 作者
     * */
    Update.prototype.controllerUpdateAnthology = function (newAnthology, oldAnthology, author) {
        var TABLE_NAME = 'article';
        var _oldAnthology = this.strEncode(oldAnthology);
        var _newAnthology = this.strEncode(newAnthology);
        var KEY = 'anthology';
        var SIGN = '=';
        var VALUE = _oldAnthology;
        return this._knex(TABLE_NAME).where(KEY, SIGN, VALUE).update({ anthology: _newAnthology });
    };
    Update.prototype.encode = function (DATA) {
        return this._crypto.dataEncode(DATA);
    };
    Update.prototype.strEncode = function (DATA) {
        return this._crypto.strEncode(DATA);
    };
    return Update;
}());
exports.default = Update;
